//
//  Hud.m
//  TrainFinder3
//
//  Created by 饶首建 on 17/3/3.
//  Copyright © 2017年 com.ikamobile.trainfinder3. All rights reserved.
//

#import "Hud.h"
#import "MBProgressHUD.h"

@interface Hud()

@property (nonatomic,weak) MBProgressHUD *mb;

@end

@implementation Hud

+(instancetype)hud{
    static dispatch_once_t onceToken;
    static Hud *mbHud = nil;
    dispatch_once(&onceToken, ^{
        mbHud = [[Hud alloc]init];
    });
    return mbHud;
}

- (instancetype)init{
    self = [super init];
    if (self) {
        
    }
    return self;
}

+ (void)hudText:(NSString *)text inView:(UIView *)view{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    if (text.length > 15) {
        hud.detailsLabel.text = text;
        hud.detailsLabel.textColor = THEM_TEXT_COLOR;
        hud.detailsLabel.font = DefaultSystemFont(14);
        [hud hideAnimated:YES afterDelay:2];
    }else{
        hud.label.text = text;
        hud.label.textColor = THEM_TEXT_COLOR;
        [hud hideAnimated:YES afterDelay:1.5];
    }
}

+ (void)hudDetailsText:(NSString *)text inView:(UIView *)view{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabel.text = text;
    hud.detailsLabel.textColor = THEM_TEXT_COLOR;
    [hud hideAnimated:YES afterDelay:1];
}

- (void)showLoading:(UIView *)view{
    _mb = [MBProgressHUD showHUDAddedTo:view animated:YES];
    _mb.mode = MBProgressHUDModeIndeterminate;
    _mb.label.text = @"正在努力加载";
    _mb.label.textColor = THEM_TEXT_COLOR;
//    _mb.backgroundView.color = [UIColor blackColor];
//    _mb.backgroundView.alpha = 0.2;
}
- (void)showLoading:(UIView *)view text:(NSString *)text{
    _mb = [MBProgressHUD showHUDAddedTo:view animated:YES];
    _mb.mode = MBProgressHUDModeIndeterminate;
    _mb.label.text = text;
    _mb.label.textColor = THEM_TEXT_COLOR;
    //    _mb.backgroundView.color = [UIColor blackColor];
    //    _mb.backgroundView.alpha = 0.2;
}
- (void)hide{
    if (_mb) {
        [_mb hideAnimated:YES];
        [_mb removeFromSuperViewOnHide];
        _mb = nil;
    }
}

@end
